<?php
ob_start();

$email = '';
$password = '';
$fullname = '';
$address = '';
$phone = '';
$DOB = '';
$sex = '';
$joinDate = date("Y-m-d H:i:s", time());
$status = '';
$avtUrl = '';
$error = '';

if(isset($_POST['btnregister']))
{
    $email = strip_tags($_POST['txtemail']);
    $password = $_POST['txtpassword'];
    $fullname = strip_tags($_POST['txtfullname']);
    $address = strip_tags($_POST['txtaddress'] . ','. $_POST['slccity']);
    $phone = $_POST['txtphone'];
    $DOB = $_POST['dob'];// . '/' .intval($_POST['slcmonth']). '/' . intval($_POST['slcday']);
    $sex = strip_tags($_POST['slcsex']);
    $status = 1;
    $avtUrl = "upload/avt_empty.jpg";
    $success = true;
    
    
    //if(!isEmail($email))
    //{
    //    $error = 'Email không hợp lệ!';
    //}
    
    if(empty($error))
    {
        $accDAO = new accountDAO();
        
        $isExitsEmail = $accDAO->checkEmailExists($email);
        
        if($isExitsEmail)
        {
            $error = "Email đã sử dụng!";
            $success = false;
        }
        
        if($success)
        {
            $accDTO = new accountDTO($accId, $email, $password, $fullname, $address, $phone, $DOB, $sex, $joinDate, $status, $avtUrl);
            $accDAO->create($accDTO);           
        }
        else
            $error = "Đăng ký thất bại!";
    }
    
}

include VIEWS_PATH . DS . 'register.php';
?>